<?php
/**
 * Object Relational Persistence Mapping Class for table: surgery_team_template_item
 *
 * @package	com.athena
 * @author	LHV
 */
class SurgeryTeamTemplateItem extends ORDataObject {

	/**#@+
	 * Fields of table: surgery_team_template_item mapped to class members
	 */
	var $surgery_team_template_item_id		= '';
	var $template_id		= '';
	var $role		= '';
	var $person_id		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'surgery_team_template_item';

	/**
	 * Primary Key
	 */
	var $_key = 'surgery_team_template_item_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'SurgeryTeamTemplateItem';

	/**
	 * Handle instantiation
	 */
	function SurgeryTeamTemplateItem() {
		parent::ORDataObject();
	}
	
	public function getTemplateItems ($templateID) {
		$sql = array(
			'cols' => 'surgery_team_template_item_id, template_id, role, person_id',
			'from' => $this->_table,
			'where'=> "template_id=$templateID"
		);
		
		$ds = new Datasource_sql();
		$ds->setup($this->_db, $sql);
		
		return $ds->toArray();
		
	}

	function addNewTemplateItem($templateItem){

		if ($templateItem['person_id'] == '') {
			return;
		}
		
		$data = array (
				'template_id'			=> $templateItem['template_id'],
				'role'					=> $templateItem['role'],
				'person_id' 			=> $templateItem['person_id']
			);		
			
		$this->populateArray($data);		
		$this->persist();
					
		return $this->surgery_team_template_item_id;
	}
	
}
?>
